<?php

namespace App\Admin\Controllers;

use App\Admin\Actions\Post\Restore;
use App\Admin\Repositories\UserInfo;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class UserInfoController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new UserInfo(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('nickName');
            $grid->column('avatar')->image();
            $grid->column('sex');
            $grid->column('tel');
            $grid->column('password');
            $grid->column('now_money');
            $grid->column('open_id');
            $grid->column('session_key');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
                $filter->scope('trashed', '回收站')->onlyTrashed();

            });
            $grid->actions(function (Grid\Displayers\Actions $actions) {
                if (request('_scope_') == 'trashed') {
                    $actions->append(new Restore(\App\Models\UserInfo::class));
                }
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new UserInfo(), function (Show $show) {
            $show->field('id');
            $show->field('nickName');
            $show->field('avatar');
            $show->field('sex');
            $show->field('tel');
            $show->field('password');
            $show->field('now_money');
            $show->field('open_id');
            $show->field('session_key');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new UserInfo(), function (Form $form) {
            $form->display('id');
            $form->text('nickName');
            $form->image('avatar');
            $form->radio('sex','性别')->options(['1'=>'男','2'=>'女']);
            $form->text('tel');
            $form->text('password');
            $form->text('now_money');
            $form->text('open_id');
            $form->text('session_key');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
